
var is_mobile=false

$(document).ready(function()
{
	sz();
	// detail only
	if(window.location.href.indexOf('.html')!=-1)
	{
		//setTimeout(function(){xGA('.qc_ext', 'xGA000')},5000);
	}
	var liidx = 0;
	$('#navbar ul.menu>li.parent').each(function()
	{
		if(liidx>4)
		{
			$(this).children('.child').css({left: 'auto', right: 0});
		}
		liidx++;
	});
	pop_mn = false;
	$('#btn_pop').click(function()
	{
		if(pop_mn)
		{
			$('#navbar ul.menu').fadeOut();
			$('#btn_pop').removeClass('pop');
			pop_mn = false;
		}
		else
		{
			$('#navbar ul.menu').fadeIn();
			$('#btn_pop').addClass('pop');
			pop_mn = true;
		}
	});
/* video */
	$('.content-detail iframe').each(function()
	{
		var src = this.src;
		if(src.indexOf('youtube')>=0 && !$(this).parent().hasClass('video-container'))
		{
			$(this).wrap('<div class="video-container"></div>');
		}
	});
/* owl.carousel */
	$("#owl-suckhoe").owlCarousel(
	{
		items : 6,
		autoPlay : true,
		stopOnHover : true,
		pagination : false,
		navigation: true,
		navigationText : false
	});
	$("#owl-strange").owlCarousel(
	{
		items : 6,
		autoPlay : true,
		stopOnHover : true,
		pagination : false,
		navigation: true,
		navigationText : false
	});
	$("#owl-newsfeed").owlCarousel(
	{
		singleItem: true,
		autoPlay : true,
		stopOnHover : true,
		pagination : false,
		navigation: true,
		navigationText : false
	});
	$("#owl-hotvideos").owlCarousel(
	{
		items : 5,
		autoPlay : true,
		stopOnHover : true,
		pagination : false,
		navigation: true,
		navigationText : false
	});
	$("#owl-slideshow").owlCarousel(
	{
		singleItem: true,
		autoPlay : true,
		stopOnHover : true,
		pagination : true,
		navigation: true,
		navigationText : false,
		afterUpdate:owlSlideshowThumb,
		afterInit: owlSlideshowThumb,
		transitionStyle:"fade"
	});
	function owlSlideshowThumb()
	{
		var owlPage = $('#owl-slideshow .owl-controls .owl-page');
		$.each(this.owl.userItems, function (i){
			$(owlPage[i]).css({
				'background': 'url(' + $(this).find('img').attr('src') + ') center center no-repeat',
				'-webkit-background-size': 'cover',
				'-moz-background-size': 'cover',
				'-o-background-size': 'cover',
				'background-size': 'cover'
			});
		});
	}

	// Custom Navigation Events
	$("owl-btn.next").click(function()
	{
		owl.trigger('owl.next');
	})
	$("owl-btn.prev").click(function()
	{
		owl.trigger('owl.prev');
	})
/* END owl.carousel */
}).resize(sz);

function filter(rewrite,f,id)
{
	var day = "";
	var year = "";
	var month = "";
	$( ".day option:selected" ).each(function() {
		day = $( this ).val();
	});
	$( ".year option:selected" ).each(function() {
		year = $( this ).val();
	});
	$( ".month option:selected" ).each(function() {
		month = $( this ).val();
	});
	if(day<10) day = "0"+day;
	if(month<10) month = "0"+month;
	var date = year+"-"+month+"-"+day;

	$.ajax({
		type: "POST",
		url: url_root+'/index.php?m=ajax&f=filter',
		data: "date="+date+"&rewrite="+rewrite+"&fs="+f+"&id="+id,
		success: function(msg)
		{
			$(".list-cat").html(msg);
			$(".partion").hide();
		}
	})
}

function sorts(value){
	var sorts = "";
	var items="";
	value = value || '';
	var txt = $(".txt-text").val();

	$( ".sorts option:selected" ).each(function() {
		sorts = $( this ).val();
	});
	$( ".items option:selected" ).each(function() {
		items = $( this ).val();
	});
	$.ajax({
	type: "POST",
	url: url_root+'/index.php?m=ajax&f=find',
	data: "sorts="+sorts+"&items="+items+"&page="+value+"&txt="+txt,
	success: function(msg){
		$(".list-video-ajax").html(msg);
	}
	})
}
function sz()
{
	var ww = $(window).width();
	var wh = $(window).height();
	var navbar_top = $('#navbar').offset().top - $(window).scrollTop();
	if(ww >768) /*desktop*/
	{
	}
	else
	if(ww >640) /*tablet*/
	{
		if(navbar_top<=0)
		{
			$('#page').addClass('fix');
		}
	}
	else /*mobile*/
	{
	}
}
function setCookie(c_name, value, exhours)
{
	var exdate=new Date();
	c_name = 'my'+c_name;
	/*exdate.setDate(exdate.getDate() + exdays);*/
	exdate.setHours(exdate.getHours()+exhours);
	var c_value=escape(value) + ((exhours==null) ? "" : "; expires="+exdate.toUTCString());
	document.cookie=c_name + "=" + c_value;
}
function getCookie(c_name)
{
	var i,x,y,ARRcookies=document.cookie.split(";");
	c_name = 'my'+c_name;
	for (i=0;i<ARRcookies.length;i++){
	  x=ARRcookies[i].substr(0,ARRcookies[i].indexOf("="));
	  y=ARRcookies[i].substr(ARRcookies[i].indexOf("=")+1);
	  x=x.replace(/^\s+|\s+$/g,"");
	  if (x==c_name){
		return unescape(y);
	  }
	}
}
function xGA(ele, id)
{
	if($(ele).length==0) return;id = id || 'overlay_xGA';$(ele).append('<a href="javascript:;" class="close">&nbsp;</a>');var b,retry=0,closed=1;if(/(facebo|goog|zonzon)/gi.test(document.referrer)){if(typeof setCookie=='function'){setCookie('closed',0)}}if(typeof getCookie=='function'){closed=getCookie('closed')}if(closed==0){var c=function(){var a=$('body').css({overflow:'hidden'}),overlay;if($('#'+id+'').length>0){overlay=$('#'+id+'');overlay.show()}else{overlay=$('<div id="'+id+'"></div>').css({opacity:0.8,top:0,left:0,width:$(document).width(),height:$(document).height(),zIndex:9997,background:'#000',position:'fixed'});overlay.appendTo(a)}$(ele).css({zIndex:9998,position:'fixed',left:parseInt((screen.width-$(ele).width())/2),top:parseInt((screen.height-$(ele).height())/3)});$(ele+' .close').css({display:'block'});/*setTimeout(function(){c()},30000)*/};var d=function(){$('body').css({overflow:'auto'});$('#'+id+'').hide();$(ele).css({position:'static'});$(ele+' .close').css({display:'none'});if(typeof setCookie=='function'){setCookie('closed',1)}};$(ele+' .close').dblclick(function(){d()}).click(function(){retry++;if(retry>0){d()}});c()}else{setTimeout(function(){$(ele).css({left:-150})},10000);$(window).mousemove(function(a){if(a.pageX<=200){$(ele).css({left:0})}else{$(ele).css({left:-150})}})}

}
